﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.Controls;
using POSSystem.BLL;

namespace WebUI
{
    public partial class SaveRefund : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

            saleLookup.OnAddIMEI = saleLookup_OnAddIMEI;
            saleLookup.OnAddProduct = saleLookup_OnAddProduct;
        }

        protected void btnScanInvoiceNo_OnClick(object sender, EventArgs e)
        {
            refund.LoadRefundInvoice(txtInvoiceNo.Text);
            updateSales.Update();
        }

        public void saleLookup_OnAddIMEI(object sender, ListItemEventArgs e)
        {
            try
            {
                string imei = e.Data["IMEI"].ToString();
                refund.AddIMEI(imei);
                updateSales.Update();
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Sales.aspx.cs", "saleLookup_OnAddIMEI", ex.StackTrace);
                ShowErrorMessage(panelErr, "(*) Error in add IMEI: " + ex.Message);
                updateErr.Update();
            }
        }

        public void saleLookup_OnAddProduct(object sender, ListItemEventArgs e)
        {
            try
            {
                int productID = (int)e.Data["ProductID"];
                int quantity = (int)e.Data["Quantity"];
                refund.AddProduct(productID, quantity);
                updateSales.Update();
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Sales.aspx.cs", "saleLookup_OnAddProduct", ex.StackTrace);
                ShowErrorMessage(panelErr, "(*) Error in add product: " + ex.Message);
                updateErr.Update();
            }
        }
    }
}
